package com.server.common.security.code.thread;

import lombok.extern.slf4j.Slf4j;

import java.util.Map;
import java.util.concurrent.*;

@Slf4j
public class ThreadHeaderUtils {

    private static final ExecutorService executorService = ThreadPoolUtils.newFixedThreadPool();

    public static void execute(Runnable runnable){
        Map<String, String> map = ThreadLocalHeaderUtils.getMap();
        executorService.execute(() -> {
            ThreadLocalHeaderUtils.setMap(map);
            try {
                runnable.run();
            }catch (Exception e){
                log.error("运行失败",e);
            }
            ThreadLocalHeaderUtils.remove();
        });
    }

}
